import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-11-12
 * Time:17:24
 */
public class CountSort {
    public static void main(String[] args) {
        int[] arr = {9,4,1,2,0,6,5,3,10,7,8};
        countSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void countSort(int[] arr) {
        int[] tmp = new int[11];
        for(int i = 0;i<arr.length;i++) {
            tmp[arr[i]]++;
        }
        int j = 0;
        for(int i = 0;i<tmp.length;i++) {
            while (tmp[i] != 0) {
                arr[j++] = i;
                tmp[i] -= 1;
            }

        }
    }

}
